package com.edu.imau.ManagerSeat;

import com.edu.imau.ManagerRoleInformation.Manager;
import com.edu.imau.ParkingDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/add3")
public class SeatAddServlet extends HttpServlet {
    private ParkingDao dao = new ParkingDao();
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //1 处理参数
        String seat_id = request.getParameter("seat_id");
        String seat_code =request.getParameter("seat_code");
        String seat_number =request.getParameter("seat_number");
        String seat_section =request.getParameter("seat_section");
        String seat_state =request.getParameter("seat_state");
        String seat_tap =request.getParameter("seat_tap");
//        int id=Integer.parseInt(id_str);
        //2 调用model
        if(seat_id == null||seat_id.equals("")){
            Seat seat = new Seat(-1,seat_code,seat_number,seat_section,seat_state,seat_tap);
            dao.addSeat(seat);

            //3 数据交给View
            response.sendRedirect("seat.jsp");
        }else{
            Seat seat = new Seat(Integer.parseInt(seat_id),seat_code,seat_number,seat_section,seat_state,seat_tap);
            dao.updateSeat(seat);

            //3 数据交给View
            response.sendRedirect("seatmanager.jsp");
        }

    }
}
